package com.wf.course.web.controller.member;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.utils.export.AllOrderExcelExporter;
import com.utils.export.CoinRechargeExcelExporter;
import com.utils.export.RechargeRecordExcelExporter;
import com.utils.page.PageBean;
import com.wf.course.service.IMemberRechargeOrderService;
import com.wf.course.web.Interceptor.LogInfo;
import com.wf.course.model.goods.GoodsOrder;
import com.wf.course.model.member.IncomeStatistics;
import com.wf.course.model.member.MemberRechargeOrder;

@Controller
@RequestMapping("MemberRechargeOrder")
public class MemberRechargeOrderController {
	
	@Autowired
	private IMemberRechargeOrderService memberRechargeOrderService;
	
	/**
	 * 
	 * @param pageNo
	 * @param pageSize
	 * @param userName
	 * @param telephone
	 * @param order_no
	 * @param transaction_id
	 * @param pay_type
	 * @param stime
	 * @param etime
	 * @param model
	 * @return
	 */
	@LogInfo("铜钱充值信息查询")
	@RequestMapping("MemberRechargeOrder")
	public String MemberRechargeOrder(
			@RequestParam(value = "pageNo", required = false) Integer pageNo,
			@RequestParam(value = "pageSize", required = false) Integer pageSize,
			@RequestParam(value = "userName",required = false) String userName,
			@RequestParam(value = "telephone",required = false) String telephone,
			@RequestParam(value = "order_no",required = false) String order_no,
			@RequestParam(value = "transaction_id",required = false) String transaction_id,
			@RequestParam(value = "pay_type",required = false) Integer pay_type,
			@RequestParam(value = "stime",required = false) String stime,
			@RequestParam(value = "etime",required = false) String etime,
			Model model){
		Map<String, Object> map = new HashMap<>();
		map.put("userName", userName);
		map.put("telephone", telephone);
		map.put("order_no", order_no);
		map.put("transaction_id", transaction_id);
		map.put("pay_type", pay_type);
		map.put("stime", stime);
		map.put("etime", etime);
		
		PageBean<MemberRechargeOrder> pageBean = new PageBean<MemberRechargeOrder>(pageNo, pageSize, null, map);
		pageBean.setUrl("MemberRechargeOrder/MemberRechargeOrder");
		memberRechargeOrderService.queryList(pageBean);
		model.addAttribute("page",pageBean);
		
		return "member/memberRechargeOrderList";
	}
	/**
	 * 铜钱充值列表展示
	 * @param pageNo
	 * @param pageSize
	 * @param userName
	 * @param telephone
	 * @param pay_type
	 * @param order_status
	 * @param model
	 * @return
	 */
	@LogInfo("铜钱充值信息列表展示")
	@RequestMapping(value="coinRechargeList")
	public String coinRechargeList(
			@RequestParam(value = "pageNo", required = false) Integer pageNo,
			@RequestParam(value = "pageSize", required = false) Integer pageSize,
			@RequestParam(value = "userName",required = false) String userName,
			@RequestParam(value = "telephone",required = false) String telephone,
			@RequestParam(value= "order_no",required = false) String order_no,
			@RequestParam(value = "pay_type",required = false) Integer pay_type,
			@RequestParam(value = "order_status",required = false) Integer order_status,
			@RequestParam(value = "sOrderPaytime",required = false) String sOrderPaytime,
			@RequestParam(value = "eOrderPaytime",required = false) String eOrderPaytime,Model model
			){
		Map<String,Object> map = new HashMap<>();
		map.put("userName", userName);
		map.put("telephone", telephone);
		map.put("order_no", order_no);
		map.put("pay_type", pay_type);
		map.put("sOrderPaytime", sOrderPaytime);
		map.put("eOrderPaytime", eOrderPaytime);
		map.put("order_status", order_status);
		PageBean<MemberRechargeOrder> pageBean = new PageBean<MemberRechargeOrder>(pageNo, pageSize, null, map);
		pageBean.setUrl("MemberRechargeOrder/coinRechargeList");
		memberRechargeOrderService.coinRechargeList(pageBean);
		model.addAttribute("page",pageBean);
		return "member/coinRechargeList";
	}
	/**
	 * 铜钱充值统计导出
	 * @param request
	 * @param userName
	 * @param telephone
	 * @param pay_type
	 * @param sOrderPaytime
	 * @param eOrderPaytime
	 * @param response
	 * @param model
	 */
	@LogInfo("导出铜钱充值统计")
	@RequestMapping(value="exportExcel",method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
	public void exportExcel(HttpServletRequest request,
			@RequestParam(value = "userName", required = false) String userName,
			@RequestParam(value = "telephone", required = false) String telephone,
			@RequestParam(value = "order_no", required = false) String order_no,
			@RequestParam(value = "pay_type",required = false) Integer pay_type,
			@RequestParam(value = "sOrderPaytime",required = false) String sOrderPaytime,
			@RequestParam(value = "eOrderPaytime",required = false) String eOrderPaytime,HttpServletResponse response,
			Model model
			){
		Map<String,Object> map = new HashMap<String,Object>();
		if(StringUtils.isNotBlank(userName)){
			map.put("userName", userName);
		}
		if(StringUtils.isNotBlank(telephone)){
			map.put("telephone", telephone);
		}
		if(StringUtils.isNotBlank(order_no)){
			map.put("order_no", order_no);
		}
		if(StringUtils.isNotBlank(sOrderPaytime)){
			map.put("sOrderPaytime", sOrderPaytime);
		}
		if(StringUtils.isNotBlank(eOrderPaytime)){
			map.put("eOrderPaytime", eOrderPaytime);
		}
		if(null !=pay_type){
			map.put("pay_type",pay_type);
		}
		PageBean<MemberRechargeOrder> pageBean = new PageBean<MemberRechargeOrder>(null,null,null,map);
		/**
		 * 导出铜钱充值列表
		 */
		List<MemberRechargeOrder> list = this.memberRechargeOrderService.queryCoinRechargeList(pageBean);
		// 实例化表以Excel格式的导出工具
		CoinRechargeExcelExporter dosExcelExporter = new CoinRechargeExcelExporter();
			// 执行导出操作
			dosExcelExporter.exportExcel(response, list);
		 
	}
	
	@LogInfo("铜钱充值详情")
	@RequestMapping(value="coinRechargeDetails/{order_no}")
	public String coinRechargeDetails(@PathVariable("order_no") String order_no,Model model){
		MemberRechargeOrder memberRechargeOrder = memberRechargeOrderService.query(order_no);
		model.addAttribute("memberRechargeOrder",memberRechargeOrder);
		return "member/coinRechargeDetails";
	}
	
	@LogInfo("总订单统计")
	@RequestMapping(value="allOrderList")
	public String allOrderList(
			@RequestParam(value = "pageNo", required = false) Integer pageNo,
			@RequestParam(value = "pageSize", required = false) Integer pageSize,
			@RequestParam(value = "orderBeginTime",required = false) String orderBeginTime,
			@RequestParam(value = "orderEndTime",required = false) String orderEndTime,Model model
			){
		Map<String, Object> map = new HashMap<>();
		map.put("orderBeginTime", orderBeginTime);
		map.put("orderEndTime", orderEndTime);
		PageBean<IncomeStatistics> pageBean = new PageBean<IncomeStatistics>(pageNo, pageSize, null, map);
		pageBean.setUrl("MemberRechargeOrder/allOrderList");
		memberRechargeOrderService.incomeStatisticsList(pageBean);
		model.addAttribute("page",pageBean);
		return "member/allOrderList";
	}
	/**
	 * 充值记录导出
	 * @param request
	 * @param response
	 * @param userName
	 * @param telephone
	 * @param order_no
	 * @param transaction_id
	 * @param pay_type
	 * @param stime
	 * @param etime
	 * @param model
	 */
	@LogInfo("充值记录导出")
	@RequestMapping(value="rechargeRecordExport",method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
	public void rechargeRecordExport(HttpServletRequest request,HttpServletResponse response,
			@RequestParam(value = "userName", required = false) String userName,
			@RequestParam(value = "telephone", required = false) String telephone,
			@RequestParam(value = "order_no",required = false) String order_no,
			@RequestParam(value = "transaction_id",required = false) String transaction_id,
			@RequestParam(value = "pay_type",required = false) Integer pay_type,
			@RequestParam(value = "stime",required = false) String stime,
			@RequestParam(value = "etime",required = false) String etime,Model model
			){
		Map<String,Object> map = new HashMap<String,Object>();
		if(StringUtils.isNotBlank(userName)){
			map.put("userName", userName);
		}
		if(StringUtils.isNotBlank(telephone)){
			map.put("telephone", telephone);
		}
		if(StringUtils.isNotBlank(stime)){
			map.put("stime", stime);
		}
		if(StringUtils.isNotBlank(etime)){
			map.put("etime", etime);
		}
		if(null !=order_no){
			map.put("order_no",order_no);
		}
		if(null != transaction_id){
			map.put("transaction_id",transaction_id);
		}
		if(null !=pay_type){
			map.put("pay_type",pay_type);
		}
		PageBean<MemberRechargeOrder> pageBean = new PageBean<MemberRechargeOrder>(null,null,null,map);
		/**
		 * 充值记录列表导出
		 */
		List<MemberRechargeOrder> list = this.memberRechargeOrderService.queryRechargeRecordList(pageBean);
		// 实例化表以Excel格式的导出工具
		RechargeRecordExcelExporter dosExcelExporter = new RechargeRecordExcelExporter();
			// 执行导出操作
			dosExcelExporter.exportExcel(response, list);
	}
	/**
	 * 总订单统计导出
	 * @param request
	 * @param response
	 * @param orderBeginTime
	 * @param orderEndTime
	 * @param model
	 */
	@LogInfo("总订单统计")
	@RequestMapping(value="allOrderexportExcel",method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
	public void allOrderexportExcel(HttpServletRequest request,HttpServletResponse response,
			@RequestParam(value = "orderBeginTime",required = false) String orderBeginTime,
			@RequestParam(value = "orderEndTime",required = false) String orderEndTime,Model model){
		Map<String,Object> map = new HashMap<>();
		map.put("orderBeginTime",orderBeginTime);
		map.put("orderEndTime",orderEndTime);
		PageBean<IncomeStatistics> pageBean = new PageBean<IncomeStatistics>(null,null,null,map);
		List<IncomeStatistics> list = memberRechargeOrderService.queryAllOrderList(pageBean);
		AllOrderExcelExporter dosExcelExporter = new AllOrderExcelExporter();
		// 执行导出操作
		dosExcelExporter.exportExcel(response, list);
	}
}
